package com.taiji.web.controller.asset;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.taiji.common.annotation.Log;
import com.taiji.common.core.controller.BaseController;
import com.taiji.common.core.domain.AjaxResult;
import com.taiji.common.enums.BusinessType;
import com.taiji.asset.domain.PropertyInfo;
import com.taiji.asset.service.IPropertyInfoService;
import com.taiji.common.utils.poi.ExcelUtil;
import com.taiji.common.core.page.TableDataInfo;

/**
 * 服务器资产信息Controller
 *
 * @author a22999
 * @date 2023-06-20
 */
@RestController
@RequestMapping("/asset/propertyInfo")
@Api(tags="服务器资产信息")
public class PropertyInfoController extends BaseController
{
    @Autowired
    private IPropertyInfoService propertyInfoService;

    /**
     * 查询服务器资产信息列表
     */
    @PreAuthorize("@ss.hasPermi('asset:propertyInfo:list')")
    @GetMapping("/list")
    @ApiOperation("查询服务器资产信息列表")
    public TableDataInfo list(PropertyInfo propertyInfo)
    {
        startPage();
        List<PropertyInfo> list = propertyInfoService.selectPropertyInfoList(propertyInfo);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('asset:propertyInfo:list')")
    @GetMapping("/server")
    @ApiOperation("查询正在启用的服务器名")
    public TableDataInfo getServer(PropertyInfo propertyInfo)
    {
        List<PropertyInfo> list = propertyInfoService.selectPropertyInfoServerAddressList(propertyInfo);
        return getDataTable(list);
    }

/*    *//**
     * 导出服务器资产信息列表
     *//*
    @PreAuthorize("@ss.hasPermi('asset:propertyInfo:export')")
    @Log(title = "服务器资产信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PropertyInfo propertyInfo)
    {
        List<PropertyInfo> list = propertyInfoService.selectPropertyInfoList(propertyInfo);
        ExcelUtil<PropertyInfo> util = new ExcelUtil<PropertyInfo>(PropertyInfo.class);
        util.exportExcel(response, list, "服务器资产信息数据");
    }*/

    /**
     * 获取服务器资产信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('asset:propertyInfo:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取服务器资产信息详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(propertyInfoService.selectPropertyInfoById(id));
    }

    /**
     * 新增服务器资产信息
     */
    @PreAuthorize("@ss.hasPermi('asset:propertyInfo:add')")
    @Log(title = "服务器资产信息", businessType = BusinessType.INSERT)
    @ApiOperation("新增服务器资产信息")
    @PostMapping
    public AjaxResult add(@RequestBody PropertyInfo propertyInfo)
    {
        int i = propertyInfoService.insertPropertyInfo(propertyInfo);
        if (i > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.error("操作失败，服务器地址不可重复");
    }

    /**
     * 修改服务器资产信息
     */
    @PreAuthorize("@ss.hasPermi('asset:propertyInfo:edit')")
    @ApiOperation("修改服务器资产信息")
    @Log(title = "服务器资产信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PropertyInfo propertyInfo)
    {
        int i = propertyInfoService.updatePropertyInfo(propertyInfo);
        if (i > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.error("操作失败，服务器地址不可重复");
    }

    /**
     * 删除服务器资产信息
     */
    @PreAuthorize("@ss.hasPermi('asset:propertyInfo:remove')")
    @ApiOperation("删除服务器资产信息")
    @Log(title = "服务器资产信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(propertyInfoService.deletePropertyInfoByIds(ids));
    }

 /*   @PreAuthorize("@ss.hasPermi('asset:propertyInfo:query')")
    @GetMapping("/server/{serverAddress}")
    public AjaxResult selectServerAddressIsExist(@PathVariable String serverAddress){

        return toAjax(propertyInfoService.selectPropertyInfoByServerAddress(serverAddress));
    }*/
}
